<html>
<head><meta charset="utf-8"><title>layout optimization of future-proofed integer enum · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html">layout optimization of future-proofed integer enum</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213973449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213973449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213973449">(Oct 20 2020 at 20:12)</a>:</h4>
<p>I wanted to make an enum that was known values and a "catch all" variant for the future ones, but couldn't find any trick to do it without requiring space for the discriminant:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(rustc_attrs)]</span><span class="w"></span>
<span class="cp">#![feature(arbitrary_enum_discriminant)]</span><span class="w"></span>

<span class="cp">#[repr(u8)]</span><span class="w"></span>
<span class="k">enum</span> <span class="nc">Thing</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">A</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">B</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">C</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[rustc_layout_scalar_valid_range_start(3)]</span><span class="w"></span>
<span class="w">    </span><span class="n">Other</span><span class="p">(</span><span class="kt">u8</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Other(Other),</span>
<span class="p">}</span><span class="w"></span>

<span class="cp">#[repr(transparent)]</span><span class="w"></span>
<span class="cp">#[rustc_layout_scalar_valid_range_start(3)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Other</span><span class="p">(</span><span class="kt">u8</span><span class="p">);</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">Other</span><span class="o">&gt;</span><span class="p">());</span><span class="w"></span>
<span class="w">    </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">Thing</span><span class="o">&gt;</span><span class="p">());</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213983461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213983461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213983461">(Oct 20 2020 at 21:46)</a>:</h4>
<p>I don't think that's possible today.  The lowering code for <code>match</code> can only use <code>switchInt</code> on specific values, not ranges of things.</p>



<a name="213983653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213983653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213983653">(Oct 20 2020 at 21:48)</a>:</h4>
<p>(This feels like a case that might always be better done with <code>#[repr(transparent)] struct Thing(u8);</code> and some associated <code>const</code>s.)</p>



<a name="213988601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213988601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213988601">(Oct 20 2020 at 22:42)</a>:</h4>
<p>That’s actually what prompted my question ;-) <a href="https://github.com/google/flatbuffers/pull/6098">https://github.com/google/flatbuffers/pull/6098</a></p>



<a name="213988789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213988789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213988789">(Oct 20 2020 at 22:45)</a>:</h4>
<blockquote>
<p>might always be better done with</p>
</blockquote>
<p>Why always?</p>



<a name="213998655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213998655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213998655">(Oct 21 2020 at 01:17)</a>:</h4>
<p>&lt;personal opinion not wearing my lang hat&gt; The more things <em>depend</em> on more-complicated layout optimizations (rather than them just being convenient) the more I think they should instead be using different (might not exist yet) language features.  Maybe custom patterns, for example. &lt;/&gt;</p>



<a name="213998762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213998762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213998762">(Oct 21 2020 at 01:19)</a>:</h4>
<p>(Aside: That PR really confused my since it said it was replacing an enum with a <em>unit</em> struct.  But it's actually a <em>newtype</em> struct, which makes sense.)</p>



<a name="213998904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213998904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213998904">(Oct 21 2020 at 01:22)</a>:</h4>
<p>I guess another other reason in this case is that it'd still be a breaking change to add <code>D</code> in the layout-optimization version, because <code>4</code> would no longer be part of <code>Other</code>, and thus all the matches would need to be updated.  And if future-proofing is needed because something might start adding more values, then it seems like it'd be good for adding those values to the enum to not be a breaking change.</p>



<a name="213998932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213998932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213998932">(Oct 21 2020 at 01:23)</a>:</h4>
<p>Interestingly, with the integer range stuff, you might actually be able to do <code>macro_rules! other { () =&gt; { Thing(4..=255) }</code> if you really wanted...</p>



<a name="213999078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/213999078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#213999078">(Oct 21 2020 at 01:26)</a>:</h4>
<p>Yup, it works:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(PartialEq, Eq)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Thing</span><span class="p">(</span><span class="kt">u8</span><span class="p">);</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">Thing</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">A</span>: <span class="nc">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">B</span>: <span class="nc">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">Thing_Other</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">Thing</span><span class="p">(</span><span class="mi">2</span><span class="o">..=</span><span class="mi">255</span><span class="p">)</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">x</span>: <span class="nc">Thing</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="o">'</span><span class="nb">static</span> <span class="kt">str</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">Thing</span>::<span class="n">A</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">"A"</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">Thing</span>::<span class="n">B</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">"B"</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">Thing_Other</span><span class="o">!</span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="s">"(other)"</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=70876e63659157a90cb63a4a70920a56">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=70876e63659157a90cb63a4a70920a56</a></p>



<a name="214046488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214046488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214046488">(Oct 21 2020 at 13:07)</a>:</h4>
<p>Now you just need to support associated macros:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="n">Thing</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">A</span>: <span class="nc">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">B</span>: <span class="nc">Self</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">Other</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">Thing</span><span class="p">(</span><span class="mi">2</span><span class="o">..=</span><span class="mi">255</span><span class="p">)</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p><code>Thing::Other! =&gt; ...</code></p>



<a name="214048895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214048895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214048895">(Oct 21 2020 at 13:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum/near/213998904">said</a>:</p>
<blockquote>
<p>I guess another other reason in this case is that it'd still be a breaking change to add <code>D</code> in the layout-optimization version, because <code>4</code> would no longer be part of <code>Other</code>, and thus all the matches would need to be updated.  And if future-proofing is needed because something might start adding more values, then it seems like it'd be good for adding those values to the enum to not be a breaking change.</p>
</blockquote>
<p>Two types of future-proofing, I suppose. I was focusing on the code being able to read unknown values from a file, e.g. the file format being newer than the library. I'd assume you'd mark the enum as non-exhaustive to force matches, but then you'd kind of want the <code>Other</code> to be the non-exhaustive target...</p>



<a name="214075918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214075918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214075918">(Oct 21 2020 at 16:22)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[repr(transparent)]</span><span class="w"></span>
<span class="cp">#[rustc_layout_scalar_valid_range_start(3)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Other</span><span class="p">(</span><span class="kt">u8</span><span class="p">);</span><span class="w"></span>
</code></pre></div>

<p>This actually seems like a safety problem, no? There's nothing to stop me from creating <code>Other(0)</code> that violates the layout.</p>



<a name="214076077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214076077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214076077">(Oct 21 2020 at 16:23)</a>:</h4>
<p>yeah, it might make sense to make field accesses for <code>layout_scalar_valid_range</code> structs unsafe</p>



<a name="214076198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214076198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214076198">(Oct 21 2020 at 16:24)</a>:</h4>
<p>but considering that this is only an internal implementation detail and not available on stable I would expect that no one cared enough to implement that</p>



<a name="214076379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214076379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214076379">(Oct 21 2020 at 16:25)</a>:</h4>
<p>is there any tracking issue for that attribute, or is it permanently internal?</p>



<a name="214076569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214076569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214076569">(Oct 21 2020 at 16:26)</a>:</h4>
<p>I guess it's under the broad <code>#![feature(rustc_attrs)]</code></p>



<a name="214077607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214077607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214077607">(Oct 21 2020 at 16:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum/near/214076077">said</a>:</p>
<blockquote>
<p>yeah, it might make sense to make field accesses for <code>layout_scalar_valid_range</code> structs unsafe</p>
</blockquote>
<p>It is already actually:</p>
<div class="codehilite"><pre><span></span><code>error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block
 --&gt; src/lib.rs:7:5
  |
7 |     Other(0);
  |     ^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr
  |
  = note: initializing a layout restricted type&#39;s field with a value outside the valid range is undefined behavior
</code></pre></div>



<a name="214077693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214077693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214077693">(Oct 21 2020 at 16:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum/near/214076569">said</a>:</p>
<blockquote>
<p>I guess it's under the broad <code>#![feature(rustc_attrs)]</code></p>
</blockquote>
<div class="codehilite"><pre><span></span><code>error[E0658]: the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable niche optimizations in libcore and will never be stable
 --&gt; src/lib.rs:2:1
  |
2 | #[rustc_layout_scalar_valid_range_start(3)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
</code></pre></div>



<a name="214078410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214078410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214078410">(Oct 21 2020 at 16:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum/near/214077607">said</a>:</p>
<div class="codehilite"><pre><span></span><code>error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block
</code></pre></div>


<p><span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span>  well then, that's what I get for not actually trying it...</p>



<a name="214417785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/layout%20optimization%20of%20future-proofed%20integer%20enum/near/214417785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum.html#214417785">(Oct 24 2020 at 09:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/122651-general/topic/layout.20optimization.20of.20future-proofed.20integer.20enum/near/214076077">said</a>:</p>
<blockquote>
<p>yeah, it might make sense to make field accesses for <code>layout_scalar_valid_range</code> structs unsafe</p>
</blockquote>
<p>True, and same for taking <code>&amp;mut</code> of such a field. Oli and me took care of that a year ago or so. :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>